import { useI18n } from "vue-i18n"
import dayjs from "dayjs";
import { GlobalStore } from "@/store/modules/global";
// import { locale } from "loong3-dv"
import "dayjs/locale/zh-cn";
import { watch } from "vue";

dayjs.locale("ch");

export default () => {
  const i18n = useI18n();
  const globalStore = GlobalStore();

  const getCurrentLanguage = () => globalStore.language

  watch(()=>globalStore.language,()=>{
    i18n.locale.value = globalStore.language
    dayjs.locale(globalStore.language)
    // locale.use(globalStore.language)
  },{immediate:true,deep:true})

  const setCurrentLanguage = (language: 'ch' | 'en') => {
    globalStore.updateLanguage(language)
  }

  return { getCurrentLanguage, setCurrentLanguage }
}